package com.tuangou.tuangoucomsumer.comsumer.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;
import com.tuangou.tuangoucomsumer.comsumer.vo.UserAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.tuangou.tuangoucomsumer.comsumer.entity.AddressEntity;
import com.tuangou.tuangoucomsumer.comsumer.service.AddressService;




/**
 * 
 *
 * @author zjb
 * @email zjb@tuangou.com
 * @date 2021-06-17 09:39:53
 */
@RestController
@RequestMapping("comsumer/address")
public class AddressController {
    @Autowired
    private AddressService addressService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("comsumer:address:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = addressService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("comsumer:address:info")
    public R info(@PathVariable("id") Integer id){
		AddressEntity address = addressService.getById(id);

        return R.ok().put("address", address);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("comsumer:address:save")
    public R save(@RequestBody AddressEntity address){
		addressService.save(address);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("comsumer:address:update")
    public R update(@RequestBody AddressEntity address){
		addressService.updateById(address);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("comsumer:address:delete")
    public R delete(@RequestBody Integer[] ids){
		addressService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/findList")
    public R findList(){
        List<UserAddress> list = addressService.findList();
        return R.ok().put("userAddress",list);
    }

}
